package com.isunland.managesystem.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.entity.BookOrderInfo;
import com.isunland.managesystem.entity.CurrentUser;
import java.util.HashMap;

/**
 * 对象功能: 预约下单
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/1/3 14:20
 */

public class AppointmentOrderListFragment extends BaseOrderListFragment {
  private static final int REQUEST_ADD = 3;
  private static final int REQUEST_DETAIL = 4;

  @Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitleCustom(R.string.appointmentOrderManagement);
  }

  @Override public String getUrl() {
    return ApiConst.URL_GET_APPOINT_ORDER_liST;
  }

  @Override public HashMap<String, String> getparameters() {
    HashMap<String, String> params = new HashMap<>();
    params.put("jobNo", CurrentUser.newInstance(mActivity).getJobNumber());//jobNo 1000622693
    return params;
  }

  @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) return;

    if (requestCode == REQUEST_ADD) {

      volleyPost();
      return;
    }
    if (requestCode == REQUEST_DETAIL) {

      volleyPost();
      return;
    }
    super.onActivityResult(requestCode, resultCode, data);
  }

  @Override public void onListItemClick(ListView l, View v, int position, long id) {
    BookOrderInfo item = mAdapter.getItem(position - mListview.getHeaderViewsCount());
    AppointmentOrderPagerActivity.newInstance(this, mActivity, item, REQUEST_DETAIL);
  }

  @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_add, menu);
    super.onCreateOptionsMenu(menu, inflater);
  }

  @Override public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case android.R.id.home:
        getActivity().finish();
        break;
      case R.id.menu_item_add:
        AppointmentOrderUpdateActivity.newInstance(this, mActivity, null, REQUEST_ADD);
        break;
      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }

  //@Override
  //public void click(View v) {
  //    if (v == null) return;
  //    switch (v.getId()) {
  //        case R.id.tv_cancel://取消
  //            if (v.getTag() instanceof Integer) {
  //                int position = (Integer) v.getTag();
  //                BookOrderInfo item = mAdapter.getItem(position);
  //                ToastUtil.show("取消" + item.getId());
  //            }
  //            return;
  //        case R.id.tv_reminder://催单
  //            if (v.getTag() instanceof Integer) {
  //                int position = (Integer) v.getTag();
  //                BookOrderInfo item = mAdapter.getItem(position);
  //                ToastUtil.show("催单" + item.getId());
  //            }
  //            return;
  //        default:
  //            break;
  //    }
  //}
}
